# 回顾守护进程
# from multiprocessing import Process
# import time
#
# def foo():
#     print(123)  # 进程启动慢,来不及打印123 主进程就完事儿,
#     time.sleep(1)
#     print("end123")
#
# def bar():
#     print(456)
#     time.sleep(3)
#     print("end456")
#
# if __name__ == '__main__':
#
#     p1 = Process(target=foo)
#     p2 = Process(target=bar)
#     p1.daemon = True
#     p1.start()
#     p2.start()
#
#     print("main-------")


# 守护线程
# from threading import Thread
# import time
#
# def task(name):
#     print(f'{name} is running')
#     time.sleep(1)
#     print(f'{name} is over')
#
#
#
# if __name__ == '__main__':
#     t = Thread(target=task,args=('mcsaoQ',))
#     t.daemon = True
#     t.start()
#
#     print('主线程')


# 分歧:

# from threading import Thread
# import time
#
# def foo():
#     print(123)
#     time.sleep(1)
#     print("end123")
#
# def bar():
#     print(456)
#     time.sleep(3)
#     print("end456")
#
# if __name__ == '__main__':
#
#     t1=Thread(target=foo)
#     t2=Thread(target=bar)
#
#     t1.daemon = True
#     t1.start()
#     t2.start()
#     print("main-------")

# 守护: 子守护主, 只要主结束,子马上结束.
# 主线程什么时候结束???
# 多线程是同一个空间,同一个进程,进程代表 空间,资源. 静态的.
# 主线程是进程空间存活在内存中的必要条件.
# 主线程: 必须要等待所有的子线程全部结束之后,你在执行完毕,进程在消失.
# 守护线程必须等待主线程结束才结束, 主线程必须等待所有的非守护线程结束才能结束.
# 守护线程: 必须等待所有的非守护线程以及主线程结束之后才能够结束.

# a = 1
#
# b = 2
#
# def func():
#     time.sleep(3)
#     print('in func')
#
# func()
#



from threading import Thread
import time

def foo():
    print(123)
    time.sleep(3)
    print("end123")

def bar():
    print(456)
    time.sleep(1)
    print("end456")

if __name__ == '__main__':

    t1=Thread(target=foo)
    t2=Thread(target=bar)

    t1.daemon = True
    t1.start()
    t2.start()
    print("main-------")
